document.addEventListener('DOMContentLoaded', () => {
    // 每秒更新
    setInterval(updateClock, 1000);
    updateClock(); // 立即显示
});

function updateClock() {
    const now = new Date();
    const dateDiv = document.getElementById('realTimeDate');
    const clockDiv = document.getElementById('realTimeClock');

    // 日期和星期
    const year = now.getFullYear();
    const month = (now.getMonth() + 1).toString().padStart(2, '0');
    const date = now.getDate().toString().padStart(2, '0');
    const weekDays = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'];
    
    // 时间
    const hours = now.getHours().toString().padStart(2, '0');
    const minutes = now.getMinutes().toString().padStart(2, '0');
    const seconds = now.getSeconds().toString().padStart(2, '0');

    // 更新显示内容
    dateDiv.innerHTML = `
        <div class="date">${year}-${month}-${date}</div>
        <div class="weekday">${weekDays[now.getDay()]}</div>
    `;

    clockDiv.innerHTML = `
        <div class="time-hour">${hours}</div>
        <div class="time-colon">:</div>
        <div class="time-minute">${minutes}</div>
        <div class="time-colon">:</div>
        <div class="time-second">${seconds}</div>
    `;
}